package net.lzzy.practices.repositories;

import net.lzzy.practices.entities.User;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.UUID;

/**
 * @author Jaymo on 2022/5/9.
 * Description:
 *
 */
public interface UserRepository extends JpaRepository<User, UUID> {
    /**
     *
     * 登录的接口
     * @param userName 用户名
     * @param password 密码
     * @return User
     */
    User findUserByUserNameAndPassword(String userName, String password);

    /** 用户查询接口
     * @param userName
     * @return
     */
    Integer countByUserName(String userName);
    Integer countAllBy();

    List<User> findAllByOrderByUpdateTimeDesc();

    List<User> findAllByOrderByUpdateTimeDesc(PageRequest pageRequest);

    List<User> findUserByApplyTeacherOrderByUpdateTimeDesc(boolean applying);

    @Query("select u from User u where  u.userName like concat('%',:kw,'%') or u.nickName like concat('%',:kw,'%') " +
            "or u.email like concat('%',:kw,'%') or u.phone like concat('%',:kw,'%') ")
    List<User> findByQuery(@Param("kw") String kw);

    /**
     * 返回指定用户的投影（salt）
     * param userName 用户名
     *
     * @return Userprojection
     */

    List<UserProjection> findUserByUserName(String userName);

}